package club.emergency.wechat.resource_study.search.provider.impl;

import club.emergency.wechat.common.response.StatusCode;
import club.emergency.wechat.common.response.ResponseEntity;
import club.emergency.wechat.model.resource_study.ResourceStudy;
import club.emergency.wechat.persistence.resource_study.ResourceStudyMapper;
import club.emergency.wechat.resource_study.search.ResourceStudySearch;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

/**
 * Create with IntelliJ IDEA
 * Project Name: wechat
 * Package Name: club.emergency.wechat.resource_study.search.provider.impl
 * Date: 2018/12/21
 *
 * @author: 快乐的小菌菌
 * Description:
 */
@RestController
public class ResourceStudySearchImpl implements ResourceStudySearch {

    private ResourceStudyMapper resourceStudyMapper;

    public ResourceStudySearchImpl(ResourceStudyMapper resourceStudyMapper) {
        this.resourceStudyMapper = resourceStudyMapper;
    }

    @Override
    public String flipList(@RequestParam(value = "resourceCategory", required = false) String resourceCategory, @RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize) {
        QueryWrapper<ResourceStudy> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(Objects.nonNull(resourceCategory), "resource_category", resourceCategory);
        queryWrapper.orderByDesc("modify_time");
        Page<ResourceStudy> page = new Page<>(pageNo, pageSize);
        IPage<ResourceStudy> resourceStudyIPage = resourceStudyMapper.selectPage(page, queryWrapper);
        return ResponseEntity.ok(StatusCode.DB_SEARCH_OK, "查询资料学习数据", resourceStudyIPage);
    }
}
